package com.imooc.long5zb.dao;

import com.imooc.long5zb.entity.User;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import javax.transaction.Transactional;

public interface UserRepository extends JpaRepository<User, Integer> {

    @Query("select u from User u")
    Page<User> findAll(Pageable pageable);

    User findByUserName(String username);

    @Transactional
    @Modifying
    @Query("update User set user_name = ?1 where id = ?2")
    int updateById(String userName, Integer id);
}
